#include<bits/stdc++.h>
using namespace std;
#define int long long

int f[40001];
int wi[100001], vi[100001], mi[1000001];

signed main()
{
	int n, w;
	cin>>n>>w;
	for(int i = 1;i <= n;i++)
		cin>>vi[i]>>wi[i]>>mi[i];
	for(int i = 1;i <= n;i++)
	{
		for(int j = w;j >= wi[i];j--)
		{
			for(int k = 0;k <= mi[i];k++)
			{
				if(k*wi[i] <= j)
					f[j] = max(f[j-k*wi[i]]+vi[i]*k, f[j]);
			}
		}
	}
	cout<<f[w];
	return 0;
}

